import 'package:flutter/material.dart';

class LearnTabRouterPage extends StatefulWidget {
  const LearnTabRouterPage({super.key});
  @override
  State<LearnTabRouterPage> createState() => _LearnTabRouterPageState();
}

class _LearnTabRouterPageState extends State<LearnTabRouterPage> {
  final PageController _controller = PageController(
      initialPage: 0 //默认为0，可以不填写
  );
  int _pageIndex = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _pageIndex,
        onTap: (int index) {
          print(index);
          setState(() {
            _pageIndex = index;
          });
          _controller.jumpToPage(index);
        },
        type: BottomNavigationBarType.fixed,
        unselectedItemColor: Colors.black,
        selectedItemColor: Colors.red,
        unselectedFontSize: 12,
        selectedFontSize: 12,
        items: const [
          BottomNavigationBarItem(label: "1", icon:Icon(Icons.directions_car),activeIcon:Icon(Icons.directions_car)),
          BottomNavigationBarItem(label: "2", icon:Icon(Icons.directions_car),activeIcon:Icon(Icons.directions_car)),
          BottomNavigationBarItem(label: "3", icon:Icon(Icons.directions_car),activeIcon:Icon(Icons.directions_car)),
          BottomNavigationBarItem(label: "4", icon:Icon(Icons.directions_car),activeIcon:Icon(Icons.directions_car)),
        ],
      ),
      body: PageView(
        controller: _controller,
        children: const [
          Center(child: Text("1",style:TextStyle(fontSize:12,color: Colors.black))),
          Center(child: Text("2",style:TextStyle(fontSize:12,color: Colors.black))),
          Center(child: Text("3",style:TextStyle(fontSize:12,color: Colors.black))),
          Center(child: Text("4",style:TextStyle(fontSize:12,color: Colors.black)))
        ],
      ),
    );
  }
}
